/**
 *
 */
package org.whuims.pois.action;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.whuims.pois.hibernate.BaseDao;
import org.whuims.pois.model.Clickedrecord;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 记录用户点击过的链接地址
 *
 * @author herochen
 * @date 2010-9-1  @time 下午08:27:11
 */
public class LogAction extends Action {


    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request, HttpServletResponse response) {
        String titleLink = request.getParameter("link");

        String ip = request.getRemoteAddr();
        //System.out.println("IP: "+ip);
        String referer = request.getHeader("referer");
        //System.out.println("Refer: " + referer);
        //添加日志
        Clickedrecord clickedrecord = new Clickedrecord();
        clickedrecord.setIp(ip);
        clickedrecord.setClicktime(new Timestamp(new Date().getTime()));
        clickedrecord.setReferer(referer);
        clickedrecord.setTitlelink(titleLink);
        new BaseDao().create(clickedrecord);
        return mapping.findForward("success");
    }

}
